package com.service;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dao.ProductionDAO;
import com.entity.Production;

@Transactional
@Service
public class ProductionService {
	@Autowired
	private ProductionDAO productionDAO;
	public List<Production> findByCategory(String categoryId){
		if(StringUtils.isEmpty(categoryId)){
			return this.productionDAO.findAll(Production.INSERT_TIME);
		}
		return this.productionDAO.findByCategory(Integer.parseInt(categoryId), Production.INSERT_TIME);
	}
	public List<Production> findByCategory(int categoryId){
		return this.productionDAO.findByCategory(categoryId, Production.INSERT_TIME);
	}
	public List<Production> findByCategoryInPage(String categoryId, int start, int limit){
		if(StringUtils.isEmpty(categoryId)){
			return this.productionDAO.findAllInPage(start, limit, Production.INSERT_TIME);
		}
		return this.productionDAO.findByCategoryInPage(Integer.parseInt(categoryId), Production.INSERT_TIME, start, limit);
	}
	public List<Production> findByCategoryInPage(Integer categoryId, int start, int limit){
		if(categoryId == null){
			return this.productionDAO.findAllInPage(start, limit, Production.INSERT_TIME);
		}
		return this.productionDAO.findByCategoryInPage(categoryId, Production.INSERT_TIME, start, limit);
	}
	public int countByCategory(String categoryId){
		if(StringUtils.isEmpty(categoryId)){
			return this.productionDAO.findAllCount().intValue();
		}
		return this.productionDAO.countByCategory(Integer.parseInt(categoryId)).intValue();
	}
	public int countByCategory(Integer categoryId){
		if(categoryId == null){
			return this.productionDAO.findAllCount().intValue();
		}
		return this.productionDAO.countByCategory(categoryId).intValue();
	}
	public List<Production> findHotProduct(){
		return this.productionDAO.findHotProduct();
	}
	public List<Production> findTopProduct(){
		return this.productionDAO.findTopProduct();
	}
	public Production findById(int id){
		return this.productionDAO.find(id);
	}
}
